
''
''
'' This file is part of FreeBASIC Regular Expressions Library
''
''

#Ifndef AndAlso
	#Define AndAlso And
#EndIf

#Include "compiler.bas"
#Include "fbregexp.bi"


Namespace FB
	
	
	'' Matches
	
	Property Matches.Count As Integer
		Return iCount
	End Property
	
	Property Matches.Item(Index As Integer) As Match
		If Index >= 0 And Index < iCount Then Return pItem[Index]
	End Property
	
	Property Matches.Item(Index As Integer, m As Match)
		If Index >= 0 And Index < iCount Then pItem[Index] = m
	End Property
	
	Sub Matches.Add(m As Match)
		If iCount = iSize Then
			iSize += 5
			pItem = ReAllocate(pItem, SizeOf(Match) * iSize)
		EndIf
		pItem[iCount] = m
		iCount += 1
	End Sub
	
	Sub Matches.Clear
		DeAllocate pItem
		pItem = 0
		iSize = 0
		iCount = 0
	End Sub
	
	Destructor Matches
		Clear
	End Destructor
	
	
	'' RegExp
	
	Constructor RegExp(p As String = "", i As Boolean = False, g As Boolean = False, m As Boolean = False) 
		
		s_Pattern = p
		b_IgnoreCase = i
		b_Global = g
		b_Multiline = m
		
		reCompiler = New RegExpLib.Compiler
		
		bCompiled = False
		
	End Constructor
	
	Destructor RegExp
		If reCompiler <> 0 Then Delete reCompiler
		reCompiler = 0
	End Destructor
	
	
	Property RegExp.Pattern As String
		Return s_Pattern
	End Property
	
	Property RegExp.Pattern(value As String)
		s_Pattern = value
		bCompiled = False
	End Property
	
	Property RegExp.IgnoreCase As Boolean
		Return b_IgnoreCase
	End Property
	
	Property RegExp.IgnoreCase(value As Boolean)
		b_IgnoreCase = value
		bCompiled = False
	End Property
	
	Property RegExp.Global As Boolean
		Return b_Global
	End Property
	
	Property RegExp.Global(value As Boolean)
		b_Global = value
		bCompiled = False
	End Property
	
	Property RegExp.Multiline As Boolean
		Return b_Multiline
	End Property
	
	Property RegExp.Multiline(value As Boolean)
		b_Multiline = value
		bCompiled = False
	End Property
	
	Function RegExp.Test(inputString As String) As Boolean
		
		If Not Compile Then Return False
		
	End Function
	
	
	Function RegExp.Compile As Boolean
		
		If Not bCompiled Then
			
			reCompiler->Pattern = s_Pattern
			reCompiler->IgnoreCase = b_IgnoreCase
			reCompiler->Multiline = b_Multiline
			
			bCompiled = reCompiler->Compile
			
		EndIf
		
		Return bCompiled
			
	End Function
	
End Namespace